/**
 * 工程名: HelloMyFriend
 * 文件名: FileUtils.java
 * 包名: com.stdroom.hellomyfriend.common
 * 日期: 2013-4-30上午9:54:00
 * Copyright (c) 2013, 北京联龙博通 All Rights Reserved.
 *
*/

package com.stdroom.hellomyfriend.common;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

/**
 * 类名: FileUtils <br/>
 * 功能: TODO 添加功能描述. <br/>
 * 日期: 2013-4-30 上午9:54:00 <br/>
 *
 * @author   "lx"
 * @version  	 
 */
public class FileUtils {
	
	
	/**
	 * makeXML:(根据文件生成短信xml). <br/>
	 *
	 * TODO(以空行或者文件末尾为一条短信的结束).<br/>
	 *
	 * @author "lx"
	 * @param category	所属分类
	 * @param inputFile	输入文件
	 * @param outpuFile	输出文件
	 * @param tagbean	输出标签
	 * @since 1.0
	 */
	public void makeXMLmain(ArrayList<String> category, ArrayList<String> tagbean, String inputFile , String outputFile){
		
		File infile = new File(inputFile);
		File outFile = new File(outputFile);
		try {
			InputStreamReader is = new InputStreamReader(new FileInputStream(infile),"UTF-8");
			BufferedReader br = new BufferedReader(is);
			OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8");
			BufferedWriter bw = new BufferedWriter(os);
			String s ;
			StringBuffer sb = new StringBuffer();
			while((s = br.readLine()) != null){
				if(s!=""){
					bw.write(s+"\r\n");
				}
			}
			bw.flush();
			bw.close();
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch(IOException e){
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	public void makeXmlHead(FileWriter fw){
		
		StringBuffer sb = new StringBuffer();
		sb.append("<?xml version=1.0 encodeing=\"utf-8\"?>");
		
		try {
			fw.write(sb.toString());
		} catch (IOException e) {
			
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		
	}
	
	public void writetoFile(String string,File outFile) throws IOException,UnsupportedEncodingException, FileNotFoundException{
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8");
		BufferedWriter bw = new BufferedWriter(osw);
		bw.write(string);
		bw.close();
		
	}
}

